package com.woniuxy.util;

import com.woniuxy.util.exception.WoniuxyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.AccessDeniedException;


@RestControllerAdvice//全局异常处理类
public class GlobalExceptionHandler {


    @ExceptionHandler(WoniuxyException.class)
    public Result handleWoniuxyException(WoniuxyException e){
        return Result.fail(e.getCode(),e.getMessage(),null);
    }


//    @ExceptionHandler(Exception.class)
//    public Result handleException(Exception e){
//        e.printStackTrace();
//        System.out.println(e.getMessage());
//        return Result.fail(500,"服务器繁忙",null);
//    }

    @ExceptionHandler(AccessDeniedException.class)
    public Result handleAccessDeniedExceptionException(AccessDeniedException e){
//       e.printStackTrace();
        System.out.println(e.getMessage());
        return Result.fail(503,e.getMessage(),null);
    }
}
